package com.ruoyi.web.controller.system;

import com.ruoyi.system.domain.TourGroupMember;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.service.ITourGroupMemberService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("tourgroupmember")
@ResponseBody
public class TourGroupMemberController {

    @Resource
    private ITourGroupMemberService iTourGroupMemberService;

    @GetMapping("/list")
    public AjaxResult list() {
        try {
            List<TourGroupMember> TourGroupMembers = iTourGroupMemberService.selectMemberList();
            System.out.println(TourGroupMembers);
            return AjaxResult.success(TourGroupMembers);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("发生错误");
        }
    }

    @PostMapping(path = "/create")
    public AjaxResult addMember(@RequestBody TourGroupMember tourGroupMember) {
        try {
            int Result = iTourGroupMemberService.addMember(tourGroupMember);
            return AjaxResult.success(Result);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("发生错误");
        }
    }

    @PostMapping(path = "/update")
    public AjaxResult updateMember(@RequestBody TourGroupMember tourGroupMember) {
        try {
            String Result = iTourGroupMemberService.updateMember(tourGroupMember);
            return AjaxResult.success(Result);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("发生错误");
        }
    }

    @PostMapping(path = "/delete")
    public AjaxResult deleteMember(@RequestBody TourGroupMember tourGroupMember) {
        try {
            String Result = iTourGroupMemberService.deleteMember(tourGroupMember.getId());
            return AjaxResult.success(Result);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("发生错误");
        }
    }
}
